
package com.lzb.compressmaster.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.AttachPopupView;
import com.lzb.compressmaster.R;

public class FileEditDialog extends AttachPopupView implements View.OnClickListener {

    private TextView tvEdit;
    private TextView tvAddFolder;
    private boolean isHideAdd;

    public FileEditDialog(@NonNull Context context) {
        super(context);
    }

    public void setHideAdd(boolean hideAdd) {
        isHideAdd = hideAdd;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_file_edit;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        tvEdit = findViewById(R.id.tvEdit);
        tvAddFolder = findViewById(R.id.tvAddFolder);

        if (isHideAdd) {
            tvAddFolder.setVisibility(View.GONE);
        } else {
            tvAddFolder.setVisibility(View.VISIBLE);
        }

        tvEdit.setOnClickListener(this);
        tvAddFolder.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvEdit) {
            dismiss();
            if (listener != null) {
                listener.clickEdit();
            }
        } else if (id == R.id.tvAddFolder) {
            dismiss();
            if (listener != null) {
                listener.clickAdd();
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickEdit();

        void clickAdd();
    }

}
